package Member;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JMenuItem;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Dimension;

public class Member extends JFrame {

	private JPanel contentPane;
	private JMenuBar menuBar;
	private JMenu mnInput;
	private JMenuItem mntmInput;
	private JMenuItem mntmOutput;
	
	private Data6[] d = new Data6[10];
	private JMenuItem mntmModify;
	private JMenuItem mntmDelete;
	//실제 배열의 수와 맞는지 d[i]번째의 데이터가 있는지 확인해야 한다.
	
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Member frame = new Member();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Member() {
		setSize(new Dimension(450, 500));
		//Sample Data input
		d[0]=new Data6();
		d[0].name = "Kim";
		d[0].address = "Seoul";
		d[0].number = "111-111";
		d[0].email = "Real@naver.com";
		d[0].age = 28;
		
		d[1]=new Data6();
		d[1].name = "Lee";
		d[1].address = "Busan";
		d[1].number = "222-222";
		d[1].email = "Real@nate.com";
		d[1].age = 99;
		
		d[2]=new Data6();
		d[2].name = "Hong";
		d[2].address = "New York";
		d[2].number = "333-333";
		d[2].email = "Hong@naver.com";
		d[2].age = 35;
		
		setTitle("Member Management Program");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 450);
		setJMenuBar(getMenuBar_1());
		contentPane = new JPanel();
		contentPane.setSize(new Dimension(450, 500));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
	}

	private JMenuBar getMenuBar_1() {
		if (menuBar == null) {
			menuBar = new JMenuBar();
			menuBar.add(getMnInput());
		}
		return menuBar;
	}
	private JMenu getMnInput() {
		if (mnInput == null) {
			mnInput = new JMenu("Member Manage");
			mnInput.add(getMntmInput());
			mnInput.add(getMntmOutput());
			mnInput.add(getMntmModify());
			mnInput.add(getMntmDelete());
		}
		return mnInput;
	}
	private JMenuItem getMntmInput() {
		if (mntmInput == null) {
			mntmInput = new JMenuItem("Input");
			mntmInput.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					
					Input i = new Input();
					i.setD(d);
					contentPane.removeAll();
					contentPane.add(i);
					contentPane.updateUI();
					
				}
			});
		}
		return mntmInput;
	}
	private JMenuItem getMntmOutput() {
		if (mntmOutput == null) {
			mntmOutput = new JMenuItem("Output");
			mntmOutput.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {					
					Output o = new Output();
					o.setD(d);
					contentPane.removeAll();
					contentPane.add(o);
					contentPane.updateUI();
					
				}
			});
		}
		return mntmOutput;
	}
	private JMenuItem getMntmModify() {
		if (mntmModify == null) {
			mntmModify = new JMenuItem("Modify");
			mntmModify.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Modify m = new Modify();
					m.setD(d);
					contentPane.removeAll();			
					contentPane.add(m);
					contentPane.updateUI();
				}
			});
			
		}
		return mntmModify;
	}
	private JMenuItem getMntmDelete() {
		if (mntmDelete == null) {
			mntmDelete = new JMenuItem("Delete");
			mntmDelete.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					Delete dl = new Delete();
					dl.setD(d);
					contentPane.removeAll();			
					contentPane.add(dl);
					contentPane.updateUI();
				}
			});
		}
		return mntmDelete;
	}
}
